package class183;

// 点分治，也叫重心分解，java版
// 一共有n个节点，给定n-1条边，每条边有边权，所有节点组成一棵树
// 一共有m条查询，每条查询给定数字k，打印树上距离为k的点对是否存在
// 1 <= n <= 10^4    1 <= 边权 <= 10^4
// 1 <= m <= 100     1 <= k <= 10^7
// 测试链接 : https://www.luogu.com.cn/problem/P3806
// 提交以下的code，提交时请把类名改成"Main"，可以通过所有测试用例

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Code01_CentroidDecomposition1 {

	public static int MAXN = 10001;
	public static int MAXM = 101;
	public static int MAXV = 10000001;
	public static int n, m;

	public static int[] query = new int[MAXM];
	public static int maxq;

	public static int[] head = new int[MAXN];
	public static int[] nxt = new int[MAXN << 1];
	public static int[] to = new int[MAXN << 1];
	public static int[] weight = new int[MAXN << 1];
	public static int cntg;

	public static boolean[] vis = new boolean[MAXN];
	public static int[] siz = new int[MAXN];
	public static int[] maxPart = new int[MAXN];
	public static int total;
	public static int centroid;

	public static int[] curDis = new int[MAXN];
	public static int cntc;

	public static int[] allDis = new int[MAXN];
	public static int cnta;

	public static boolean[] check = new boolean[MAXV];

	public static boolean[] ans = new boolean[MAXM];

	public static void addEdge(int u, int v, int w) {
		nxt[++cntg] = head[u];
		to[cntg] = v;
		weight[cntg] = w;
		head[u] = cntg;
	}

	public static void getCentroid(int u, int fa) {
		siz[u] = 1;
		maxPart[u] = 0;
		for (int e = head[u]; e > 0; e = nxt[e]) {
			int v = to[e];
			if (v != fa && !vis[v]) {
				getCentroid(v, u);
				siz[u] += siz[v];
				maxPart[u] = Math.max(siz[v], maxPart[u]);
			}
		}
		maxPart[u] = Math.max(maxPart[u], total - siz[u]);
		if (centroid == 0 || maxPart[u] < maxPart[centroid]) {
			centroid = u;
		}
	}

	public static void dfs(int u, int fa, int dis) {
		if (dis > maxq) {
			return;
		}
		curDis[++cntc] = dis;
		for (int e = head[u]; e > 0; e = nxt[e]) {
			int v = to[e];
			if (v != fa && !vis[v]) {
				dfs(v, u, dis + weight[e]);
			}
		}
	}

	public static void calc(int u) {
		cnta = 0;
		for (int e = head[u]; e > 0; e = nxt[e]) {
			int v = to[e];
			int w = weight[e];
			if (!vis[v]) {
				cntc = 0;
				dfs(v, u, w);
				for (int i = 1; i <= m; i++) {
					for (int j = 1; j <= cntc; j++) {
						if (query[i] - curDis[j] >= 0) {
							ans[i] |= check[query[i] - curDis[j]];
						}
					}
				}
				for (int i = 1; i <= cntc; i++) {
					allDis[++cnta] = curDis[i];
					check[curDis[i]] = true;
				}
			}
		}
		for (int i = 1; i <= cnta; i++) {
			check[allDis[i]] = false;
		}
	}

	public static void solve(int u) {
		vis[u] = true;
		check[0] = true;
		calc(u);
		for (int e = head[u]; e > 0; e = nxt[e]) {
			int v = to[e];
			if (!vis[v]) {
				total = siz[v];
				centroid = 0;
				getCentroid(v, u);
				solve(centroid);
			}
		}
	}

	public static void main(String[] args) throws Exception {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		n = in.nextInt();
		m = in.nextInt();
		for (int i = 1, u, v, w; i < n; i++) {
			u = in.nextInt();
			v = in.nextInt();
			w = in.nextInt();
			addEdge(u, v, w);
			addEdge(v, u, w);
		}
		for (int i = 1; i <= m; i++) {
			query[i] = in.nextInt();
			maxq = Math.max(maxq, query[i]);
		}
		total = n;
		centroid = 0;
		getCentroid(1, 0);
		solve(centroid);
		for (int i = 1; i <= m; i++) {
			if (ans[i]) {
				out.println("AYE");
			} else {
				out.println("NAY");
			}
		}
		out.flush();
		out.close();
	}

	// 读写工具类
	static class FastReader {
		private final byte[] buffer = new byte[1 << 20];
		private int ptr = 0, len = 0;
		private final InputStream in;

		FastReader(InputStream in) {
			this.in = in;
		}

		private int readByte() throws IOException {
			if (ptr >= len) {
				len = in.read(buffer);
				ptr = 0;
				if (len <= 0)
					return -1;
			}
			return buffer[ptr++];
		}

		int nextInt() throws IOException {
			int c;
			do {
				c = readByte();
			} while (c <= ' ' && c != -1);
			boolean neg = false;
			if (c == '-') {
				neg = true;
				c = readByte();
			}
			int val = 0;
			while (c > ' ' && c != -1) {
				val = val * 10 + (c - '0');
				c = readByte();
			}
			return neg ? -val : val;
		}
	}

}
